//
//  ALPS_ColumnTableViewCell.m
//  Alps
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_ColumnTableViewCell.h"
#import "ALPS_MainListenCollectionViewCell.h"
#import "ALPS_SpecialIntroViewController.h"

@interface ALPS_ColumnTableViewCell ()
/** 存放model的数组 */
@property (nonatomic, strong) NSMutableArray *arr;
@end

@implementation ALPS_ColumnTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.leftArrow = [[UIImageView alloc] init];
        [self.contentView addSubview:_leftArrow];
        [self.leftArrow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 58 - 10, 0, ScreeHeight / 2.668 - ScreeHeight / 13 + 10, ScreeWidth - ScreeHeight / 16.675));
        }];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(5, 30, ScreeHeight / 2.668 - ScreeHeight / 12.13 + 15, 150));
        }];
        
        self.moreLabel = [[UILabel alloc] init];
        self.moreLabel.font = [UIFont systemFontOfSize:15];
        self.moreLabel.textColor = [UIColor grayColor];
        self.moreLabel.textAlignment = 2;
        [self.contentView addSubview:_moreLabel];
        [self.moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(-10, 200, ScreeHeight / 2.668 - ScreeHeight / 12.13, 15));
        }];
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
        [self.contentView addSubview:_lineLabel];
        [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 2.668, 0, 0, 0));
        }];
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(ScreeWidth, ScreeHeight / 6.67);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, ScreeHeight / 12.13 - 10, ScreeWidth, ScreeHeight / 2.668 - ScreeHeight / 12.13) collectionViewLayout:flowLayout];
        self.collectionView.backgroundColor = [UIColor whiteColor];
        self.collectionView.scrollEnabled = NO;
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.collectionView.showsVerticalScrollIndicator = NO;
        [self.contentView addSubview:_collectionView];
        
        [self.collectionView registerClass:[ALPS_MainListenCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}
    return self;
}

- (void)setModel:(ALPS_MainModel *)model
{
    if (_model != model) {
        _model = model;
        self.titleLabel.text = model.title;
        self.moreLabel.text = @"更多";
        self.leftArrow.image = [UIImage imageNamed:@"toolbar_play_n"];
    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ALPS_MainListenCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    self.arr = [NSMutableArray array];
    for (NSDictionary *dic in self.model.list) {
        ALPS_MainModel *model = [[ALPS_MainModel alloc] initWithDic:dic];
        [self.arr addObject:model];
    }
    cell.model = [self.arr objectAtIndex:indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ALPS_MainModel *model = [self.arr objectAtIndex:indexPath.row];
    _block(model.specialId);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
